package cn.iocoder.yudao.module.member.api.user;

import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.module.member.api.user.dto.CrmMemberUserRespDTO;
import cn.iocoder.yudao.module.member.dal.dataobject.user.MemberUserGasAddressDO;
import cn.iocoder.yudao.module.member.dal.mysql.user.CrmMemberUserMapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class CrmMemberUserApiImpl implements CrmMemberUserApi{
    @Resource
    private CrmMemberUserMapper crmMemberUserMapper;


    @Override
    public List<CrmMemberUserRespDTO> selectCrmList(CrmMemberUserRespDTO respDTO) {
        LambdaQueryWrapperX<MemberUserGasAddressDO> wrapperX = new LambdaQueryWrapperX<>();
        wrapperX.likeIfPresent(MemberUserGasAddressDO :: getName, respDTO.getName())
                .eqIfPresent(MemberUserGasAddressDO :: getAccountType, respDTO.getAccountType())
                .eqIfPresent(MemberUserGasAddressDO :: getCode, respDTO.getCode())
                .eqIfPresent(MemberUserGasAddressDO :: getMobile, respDTO.getMobile());

        return BeanUtils.toBean(crmMemberUserMapper.selectList(wrapperX), CrmMemberUserRespDTO.class);
    }

    @Override
    public CrmMemberUserRespDTO getCrmMemberById(Long crmMemberUserId) {
        return BeanUtils.toBean(crmMemberUserMapper.selectById(crmMemberUserId), CrmMemberUserRespDTO.class);
    }

    @Override
    public List<CrmMemberUserRespDTO> getCrmMemberByIdList(List<Long> crmMemberUserIdList) {
        LambdaQueryWrapperX<MemberUserGasAddressDO> wrapperX = new LambdaQueryWrapperX<>();
        wrapperX.in(MemberUserGasAddressDO :: getId, crmMemberUserIdList);
        return BeanUtils.toBean(crmMemberUserMapper.selectList(wrapperX), CrmMemberUserRespDTO.class);
    }
}
